import QtQuick 1.1


Rectangle {
    id: wrapper
    color: "transparent"
    x: 30

    property int myFontSize: 18

    Rectangle {
        id: splitLine
        height: 2
        width: 801
        y: parent.height - height
        color: "#f5f8fc"
    }

    Rectangle {
        id: itemIcon
        width: 80
        anchors.verticalCenter: parent.verticalCenter
        Image {
            //width: 32
            //height: 32
            anchors.verticalCenter: parent.verticalCenter
            //anchors.horizontalCenter: parent.horizontalCenter
            source: usbDiskIcon
        }
    }
    Text {
        id: itemDisk
        clip: true
        width: 85
        anchors.left: itemIcon.right
        font { pixelSize: myFontSize  }
        anchors.verticalCenter: parent.verticalCenter
        text: usbDisk
    }
    Text {
        id: itemLabel
        //clip: true
        width: 100
        //maximumLineCount: 4
        anchors.left:  itemDisk.right
        font { pixelSize: myFontSize  }
        anchors.verticalCenter: parent.verticalCenter
        text: usbDiskLable
        elide: Text.ElideRight
    }
    Text {
        id: itemVolume
        clip: true
        width: 100
        anchors.left: itemLabel.right
        font { pixelSize: myFontSize  }
        anchors.verticalCenter: parent.verticalCenter
        text: usbVolume
    }
    Text {
        id: itemFileSystem
        clip: true
        width: 170
        anchors.verticalCenter: parent.verticalCenter
        anchors.left: itemVolume.right
        font { pixelSize: myFontSize  }
        text: usbFileSystem
    }
    Rectangle {
        id: processBar
        height: 8
        color: "transparent"
        anchors.verticalCenter: parent.verticalCenter
        width: 170
        anchors.left: itemFileSystem.right
        Rectangle {
            width: 150; height:8
            radius: 10
            anchors.verticalCenter: parent.verticalCenter
            color: "#999999"
            Rectangle {
                width: usbPerVal * parent.width / 100; height: parent.height; radius: parent.radius
                color: "#0099ff"
            }
        }
    }
    Text {
        anchors.top: processBar.bottom
        anchors.bottom: parent.bottom
        anchors.left: processBar.left
        visible: { (usbPerVal == 0? false: true) }
        text: {
            if (usbPerVal == 100) {
                return "Done"
            }
            else {
                return "processing ..."
            }
        }
    }
    Button {
        id: optBtn
        //width: 70; height: 30
        width: 95
        anchors.left: processBar.right
        anchors.verticalCenter: parent.verticalCenter
        MouseArea {
            z: 1
            anchors.fill: parent
            onPressed: {
                optBtn.btnIcon = "images/Button-Press.png"
            }
            onReleased: {
                optBtn.btnIcon = "images/Button-Normal.png"
            }
            onClicked: {
                if (wrapper.ListView.view.currentIndex === index) {
                    var rst = USB.popUpWarningMsg("This action will format the device and you will lost all files on that, are you sure to continue?");
                    if (!rst) {
                        return;
                    }
                    makeClonezillaDevice(index, itemDisk.text, itemLabel.text);
                    console.log("Begining make a clonezilla bootable device:" + disk.text);
                }
                else {
                    wrapper.ListView.view.currentIndex = index;
                }
            }
        }
    }
    WorkerScript {
             id: myWorker
             source: "makeBootableDevice.js"
    }

    MouseArea {
        //x: wrapper.x
        //y: wrapper.y
        width: optBtn.x
        height: wrapper.height
        onClicked: {
            wrapper.ListView.view.currentIndex = index;
        }
    }
}

